package bigDataSort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 用于排序的Mapper
 */
public class BigDataMapper extends Mapper<LongWritable, Text, LongWritable, NullWritable> {
    private LongWritable outputKey = new LongWritable();

    public void map(LongWritable key, Text value,
                    Mapper<LongWritable, Text, LongWritable, NullWritable>.Context context)
            throws IOException, InterruptedException {
        String buffer = value.toString().trim();
        if (buffer.isEmpty()) {
            return;
        }

        long target = Long.parseLong(buffer);
        outputKey.set(target);

        context.write(outputKey, NullWritable.get());
    }
}
